import 'package:flutter_mwm/util/util.dart';
import 'package:json_annotation/json_annotation.dart';
import 'dart:convert';

part 'bean.g.dart';

//需要在项目根目录运行以下命令--
// flutter packages pub run build_runner build
@JsonSerializable()
class ReturnBean {
  String code;
  String message;

  ReturnBean({this.code, this.message});

  static ReturnBean json2Bean(String result) {
    Map userMap = json.decode(result);
    return ReturnBean.fromJson(userMap);
  }

  factory ReturnBean.fromJson(Map<String, dynamic> json) =>
      _$ReturnBeanFromJson(json);

  Map<String, dynamic> toJson() => _$ReturnBeanToJson(this);
}

@JsonSerializable()
class ReturnAccountBean {
  String code;
  String message;
  AccountBean obj;

  ReturnAccountBean({this.code, this.message, this.obj});

  static ReturnAccountBean json2Bean(String result) {
    Map userMap = json.decode(result);
    return ReturnAccountBean.fromJson(userMap);
  }

  factory ReturnAccountBean.fromJson(Map<String, dynamic> json) =>
      _$ReturnAccountBeanFromJson(json);

  Map<String, dynamic> toJson() => _$ReturnAccountBeanToJson(this);
}

@JsonSerializable()
class AccountBean {
  String locked;
  String username;
  String nickname;
  String password;
  String device;
  String serial;
  String signature;

  AccountBean(
      {this.locked,
      this.username,
      this.nickname,
      this.password,
      this.device,
      this.serial,
      this.signature});

  static AccountBean json2Bean(String result) {
    Map userMap = json.decode(result);
    return AccountBean.fromJson(userMap);
  }

  factory AccountBean.fromJson(Map<String, dynamic> json) =>
      _$AccountBeanFromJson(json);

  Map<String, dynamic> toJson() => _$AccountBeanToJson(this);

  String bean2Json() => _$AccountBean2Json(this);
}

@JsonSerializable()
class WeatherBean {
  String wendu;
  String ganmao;
  String city;
  List<WeatherForecastBean> forecast;

  WeatherBean({this.wendu, this.ganmao, this.city, this.forecast});

  static WeatherBean json2Bean(String result) {
    Map userMap = json.decode(result);
    return WeatherBean.fromJson(userMap);
  }

  factory WeatherBean.fromJson(Map<String, dynamic> json) =>
      _$WeatherBeanFromJson(json);

  Map<String, dynamic> toJson() => _$WeatherBeanToJson(this);
}

@JsonSerializable()
class WeatherForecastBean {
  String fengxiang;
  String fengli;
  String high;
  String type;
  String low;
  String date;

  WeatherForecastBean(
      {this.fengxiang, this.fengli, this.high, this.type, this.low, this.date});

  static WeatherForecastBean json2Bean(String result) {
    Map userMap = json.decode(result);
    return WeatherForecastBean.fromJson(userMap);
  }

  factory WeatherForecastBean.fromJson(Map<String, dynamic> json) =>
      _$WeatherForecastBeanFromJson(json);

  Map<String, dynamic> toJson() => _$WeatherForecastBeanToJson(this);
}

@JsonSerializable()
class CityBean {
  String cityName;
  String cityLetter;

  CityBean({this.cityName, this.cityLetter});

  static CityBean json2Bean(String result) {
    Map userMap = json.decode(result);
    return CityBean.fromJson(userMap);
  }
  static List<CityBean> json2List(String result) {
    if (TextUtils.isEmpty(result)) {
      return List();
    }
    List array = json.decode(result);
    return array.map((m) => CityBean.fromJson(m)).toList();
  }

  factory CityBean.fromJson(Map<String, dynamic> json) =>
      _$CityBeanFromJson(json);

  Map<String, dynamic> toJson() => _$CityBeanToJson(this);
  String bean2Json() => _$CityBean2Json(this);

}
